
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>pypcd.tests.test_pypcd &#8212; pypcd 0.1.1 documentation</title>
    <link rel="stylesheet" href="../../../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
   
  <link rel="stylesheet" href="../../../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <h1>Source code for pypcd.tests.test_pypcd</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">this is just a basic sanity check, not a really legit test suite.</span>

<span class="sd">TODO maybe download data here instead of having it in repo</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">pytest</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">import</span> <span class="nn">tempfile</span>

<span class="n">header1</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="s2"># .PCD v0.7 - Point Cloud Data file format</span>
<span class="s2">VERSION 0.7</span>
<span class="s2">FIELDS x y z i</span>
<span class="s2">SIZE 4 4 4 4</span>
<span class="s2">TYPE F F F F</span>
<span class="s2">COUNT 1 1 1 1</span>
<span class="s2">WIDTH 500028</span>
<span class="s2">HEIGHT 1</span>
<span class="s2">VIEWPOINT 0 0 0 1 0 0 0</span>
<span class="s2">POINTS 500028</span>
<span class="s2">DATA binary_compressed</span>
<span class="s2">&quot;&quot;&quot;</span>

<span class="n">header2</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="s2">VERSION .7</span>
<span class="s2">FIELDS x y z normal_x normal_y normal_z curvature boundary k vp_x vp_y vp_z principal_curvature_x principal_curvature_y principal_curvature_z pc1 pc2</span>
<span class="s2">SIZE 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4</span>
<span class="s2">TYPE F F F F F F F F F F F F F F F F F</span>
<span class="s2">COUNT 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1</span>
<span class="s2">WIDTH 19812</span>
<span class="s2">HEIGHT 1</span>
<span class="s2">VIEWPOINT 0.0 0.0 0.0 1.0 0.0 0.0 0.0</span>
<span class="s2">POINTS 19812</span>
<span class="s2">DATA ascii</span>
<span class="s2">&quot;&quot;&quot;</span>


<div class="viewcode-block" id="pcd_fname"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.pcd_fname">[docs]</a><span class="nd">@pytest</span><span class="o">.</span><span class="n">fixture</span>
<span class="k">def</span> <span class="nf">pcd_fname</span><span class="p">():</span>
    <span class="kn">import</span> <span class="nn">pypcd</span>
    <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">pypcd</span><span class="o">.</span><span class="n">__path__</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;test_data&#39;</span><span class="p">,</span></div>
                        <span class="s1">&#39;partial_cup_model.pcd&#39;</span><span class="p">)</span>


<div class="viewcode-block" id="ascii_pcd_fname"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.ascii_pcd_fname">[docs]</a><span class="nd">@pytest</span><span class="o">.</span><span class="n">fixture</span>
<span class="k">def</span> <span class="nf">ascii_pcd_fname</span><span class="p">():</span>
    <span class="kn">import</span> <span class="nn">pypcd</span>
    <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">pypcd</span><span class="o">.</span><span class="n">__path__</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;test_data&#39;</span><span class="p">,</span></div>
                        <span class="s1">&#39;ascii.pcd&#39;</span><span class="p">)</span>


<div class="viewcode-block" id="bin_pcd_fname"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.bin_pcd_fname">[docs]</a><span class="nd">@pytest</span><span class="o">.</span><span class="n">fixture</span>
<span class="k">def</span> <span class="nf">bin_pcd_fname</span><span class="p">():</span>
    <span class="kn">import</span> <span class="nn">pypcd</span>
    <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">pypcd</span><span class="o">.</span><span class="n">__path__</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;test_data&#39;</span><span class="p">,</span></div>
                        <span class="s1">&#39;bin.pcd&#39;</span><span class="p">)</span>


<div class="viewcode-block" id="cloud_centroid"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.cloud_centroid">[docs]</a><span class="k">def</span> <span class="nf">cloud_centroid</span><span class="p">(</span><span class="n">pc</span><span class="p">):</span>
    <span class="n">xyz</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">pc</span><span class="o">.</span><span class="n">points</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)</span>
    <span class="n">xyz</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">]</span>
    <span class="n">xyz</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">[</span><span class="s1">&#39;y&#39;</span><span class="p">]</span>
    <span class="n">xyz</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">]</span></div>
    <span class="k">return</span> <span class="n">xyz</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>


<div class="viewcode-block" id="test_parse_header"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.test_parse_header">[docs]</a><span class="k">def</span> <span class="nf">test_parse_header</span><span class="p">():</span>
    <span class="kn">from</span> <span class="nn">pypcd.pypcd</span> <span class="k">import</span> <span class="n">parse_header</span>
    <span class="n">lines</span> <span class="o">=</span> <span class="n">header1</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
    <span class="n">md</span> <span class="o">=</span> <span class="n">parse_header</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;version&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;0.7&#39;</span><span class="p">)</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="s1">&#39;i&#39;</span><span class="p">])</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;size&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="p">[</span><span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">])</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;count&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;width&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">500028</span><span class="p">)</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;height&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;viewpoint&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;points&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">500028</span><span class="p">)</span></div>
    <span class="k">assert</span> <span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;data&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;binary_compressed&#39;</span><span class="p">)</span>


<div class="viewcode-block" id="test_from_path"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.test_from_path">[docs]</a><span class="k">def</span> <span class="nf">test_from_path</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">pypcd</span> <span class="k">import</span> <span class="n">pypcd</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">)</span>

    <span class="n">fields</span> <span class="o">=</span> <span class="s1">&#39;x y z normal_x normal_y normal_z curvature boundary k vp_x vp_y vp_z principal_curvature_x principal_curvature_y principal_curvature_z pc1 pc2&#39;</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">fld1</span><span class="p">,</span> <span class="n">fld2</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">fields</span><span class="p">,</span> <span class="n">fields</span><span class="p">):</span>
        <span class="k">assert</span><span class="p">(</span><span class="n">fld1</span> <span class="o">==</span> <span class="n">fld2</span><span class="p">)</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">width</span> <span class="o">==</span> <span class="mi">19812</span><span class="p">)</span></div>
    <span class="k">assert</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">)</span> <span class="o">==</span> <span class="mi">19812</span><span class="p">)</span>


<div class="viewcode-block" id="test_add_fields"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.test_add_fields">[docs]</a><span class="k">def</span> <span class="nf">test_add_fields</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">pypcd</span> <span class="k">import</span> <span class="n">pypcd</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">)</span>

    <span class="n">old_md</span> <span class="o">=</span> <span class="n">pc</span><span class="o">.</span><span class="n">get_metadata</span><span class="p">()</span>
    <span class="c1"># new_dt = [(f, pc.pc_data.dtype[f]) for f in pc.pc_data.dtype.fields]</span>
    <span class="c1"># new_data = [pc.pc_data[n] for n in pc.pc_data.dtype.names]</span>
    <span class="n">md</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;fields&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;bla&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">],</span> <span class="s1">&#39;count&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;size&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span>
          <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">]}</span>
    <span class="n">d</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">rec</span><span class="o">.</span><span class="n">fromarrays</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">)),</span>
                           <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">))))</span>
    <span class="n">newpc</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">add_fields</span><span class="p">(</span><span class="n">pc</span><span class="p">,</span> <span class="n">md</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>

    <span class="n">new_md</span> <span class="o">=</span> <span class="n">newpc</span><span class="o">.</span><span class="n">get_metadata</span><span class="p">()</span>
    <span class="c1"># print len(old_md[&#39;fields&#39;]), len(md[&#39;fields&#39;]), len(new_md[&#39;fields&#39;])</span>
    <span class="c1"># print old_md[&#39;fields&#39;], md[&#39;fields&#39;], new_md[&#39;fields&#39;]</span></div>
    <span class="k">assert</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">old_md</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">])</span><span class="o">+</span><span class="nb">len</span><span class="p">(</span><span class="n">md</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">new_md</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]))</span>


<div class="viewcode-block" id="test_path_roundtrip_ascii"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.test_path_roundtrip_ascii">[docs]</a><span class="k">def</span> <span class="nf">test_path_roundtrip_ascii</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">pypcd</span> <span class="k">import</span> <span class="n">pypcd</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">)</span>
    <span class="n">md</span> <span class="o">=</span> <span class="n">pc</span><span class="o">.</span><span class="n">get_metadata</span><span class="p">()</span>

    <span class="n">tmp_dirname</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">suffix</span><span class="o">=</span><span class="s1">&#39;_pypcd&#39;</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s1">&#39;tmp&#39;</span><span class="p">)</span>

    <span class="n">tmp_fname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tmp_dirname</span><span class="p">,</span> <span class="s1">&#39;out.pcd&#39;</span><span class="p">)</span>

    <span class="n">pc</span><span class="o">.</span><span class="n">save_pcd</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s1">&#39;ascii&#39;</span><span class="p">)</span>

    <span class="k">assert</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">))</span>

    <span class="n">pc2</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">)</span>
    <span class="n">md2</span> <span class="o">=</span> <span class="n">pc2</span><span class="o">.</span><span class="n">get_metadata</span><span class="p">()</span>
    <span class="k">assert</span><span class="p">(</span><span class="n">md</span> <span class="o">==</span> <span class="n">md2</span><span class="p">)</span>

    <span class="n">np</span><span class="o">.</span><span class="n">testing</span><span class="o">.</span><span class="n">assert_equal</span><span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">,</span> <span class="n">pc2</span><span class="o">.</span><span class="n">pc_data</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">):</span>
        <span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">)</span></div>
    <span class="n">os</span><span class="o">.</span><span class="n">removedirs</span><span class="p">(</span><span class="n">tmp_dirname</span><span class="p">)</span>


<div class="viewcode-block" id="test_path_roundtrip_binary"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.test_path_roundtrip_binary">[docs]</a><span class="k">def</span> <span class="nf">test_path_roundtrip_binary</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">pypcd</span> <span class="k">import</span> <span class="n">pypcd</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">)</span>
    <span class="n">md</span> <span class="o">=</span> <span class="n">pc</span><span class="o">.</span><span class="n">get_metadata</span><span class="p">()</span>

    <span class="n">tmp_dirname</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">suffix</span><span class="o">=</span><span class="s1">&#39;_pypcd&#39;</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s1">&#39;tmp&#39;</span><span class="p">)</span>

    <span class="n">tmp_fname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tmp_dirname</span><span class="p">,</span> <span class="s1">&#39;out.pcd&#39;</span><span class="p">)</span>

    <span class="n">pc</span><span class="o">.</span><span class="n">save_pcd</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s1">&#39;binary&#39;</span><span class="p">)</span>

    <span class="k">assert</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">))</span>

    <span class="n">pc2</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">)</span>
    <span class="n">md2</span> <span class="o">=</span> <span class="n">pc2</span><span class="o">.</span><span class="n">get_metadata</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">md2</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">k</span> <span class="o">==</span> <span class="s1">&#39;data&#39;</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">v</span> <span class="o">==</span> <span class="s1">&#39;binary&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">v</span> <span class="o">==</span> <span class="n">md</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>

    <span class="n">np</span><span class="o">.</span><span class="n">testing</span><span class="o">.</span><span class="n">assert_equal</span><span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">,</span> <span class="n">pc2</span><span class="o">.</span><span class="n">pc_data</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">):</span>
        <span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">)</span></div>
    <span class="n">os</span><span class="o">.</span><span class="n">removedirs</span><span class="p">(</span><span class="n">tmp_dirname</span><span class="p">)</span>


<div class="viewcode-block" id="test_path_roundtrip_binary_compressed"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.test_path_roundtrip_binary_compressed">[docs]</a><span class="k">def</span> <span class="nf">test_path_roundtrip_binary_compressed</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">pypcd</span> <span class="k">import</span> <span class="n">pypcd</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">)</span>
    <span class="n">md</span> <span class="o">=</span> <span class="n">pc</span><span class="o">.</span><span class="n">get_metadata</span><span class="p">()</span>

    <span class="n">tmp_dirname</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">suffix</span><span class="o">=</span><span class="s1">&#39;_pypcd&#39;</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s1">&#39;tmp&#39;</span><span class="p">)</span>

    <span class="n">tmp_fname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tmp_dirname</span><span class="p">,</span> <span class="s1">&#39;out.pcd&#39;</span><span class="p">)</span>

    <span class="n">pc</span><span class="o">.</span><span class="n">save_pcd</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s1">&#39;binary_compressed&#39;</span><span class="p">)</span>

    <span class="k">assert</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">))</span>

    <span class="n">pc2</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">tmp_fname</span><span class="p">)</span>
    <span class="n">md2</span> <span class="o">=</span> <span class="n">pc2</span><span class="o">.</span><span class="n">get_metadata</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">md2</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">k</span> <span class="o">==</span> <span class="s1">&#39;data&#39;</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">v</span> <span class="o">==</span> <span class="s1">&#39;binary_compressed&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">v</span> <span class="o">==</span> <span class="n">md</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>

    <span class="n">np</span><span class="o">.</span><span class="n">testing</span><span class="o">.</span><span class="n">assert_equal</span><span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">pc_data</span><span class="p">,</span> <span class="n">pc2</span><span class="o">.</span><span class="n">pc_data</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">tmp_dirname</span><span class="p">):</span></div>
        <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">tmp_dirname</span><span class="p">)</span>


<div class="viewcode-block" id="test_cat_pointclouds"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.test_cat_pointclouds">[docs]</a><span class="k">def</span> <span class="nf">test_cat_pointclouds</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">pypcd</span> <span class="k">import</span> <span class="n">pypcd</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="o">.</span><span class="n">from_path</span><span class="p">(</span><span class="n">pcd_fname</span><span class="p">)</span>
    <span class="n">pc2</span> <span class="o">=</span> <span class="n">pc</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="n">pc2</span><span class="o">.</span><span class="n">pc_data</span><span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">0.1</span>
    <span class="n">pc3</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">cat_point_clouds</span><span class="p">(</span><span class="n">pc</span><span class="p">,</span> <span class="n">pc2</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">fld</span><span class="p">,</span> <span class="n">fld3</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">pc</span><span class="o">.</span><span class="n">fields</span><span class="p">,</span> <span class="n">pc3</span><span class="o">.</span><span class="n">fields</span><span class="p">):</span>
        <span class="k">assert</span><span class="p">(</span><span class="n">fld</span> <span class="o">==</span> <span class="n">fld3</span><span class="p">)</span></div>
    <span class="k">assert</span><span class="p">(</span><span class="n">pc3</span><span class="o">.</span><span class="n">width</span> <span class="o">==</span> <span class="n">pc</span><span class="o">.</span><span class="n">width</span><span class="o">+</span><span class="n">pc2</span><span class="o">.</span><span class="n">width</span><span class="p">)</span>


<div class="viewcode-block" id="test_ascii_bin1"><a class="viewcode-back" href="../../../pypcd.tests.html#pypcd.tests.test_pypcd.test_ascii_bin1">[docs]</a><span class="k">def</span> <span class="nf">test_ascii_bin1</span><span class="p">(</span><span class="n">ascii_pcd_fname</span><span class="p">,</span> <span class="n">bin_pcd_fname</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">pypcd</span> <span class="k">import</span> <span class="n">pypcd</span>
    <span class="n">apc1</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">point_cloud_from_path</span><span class="p">(</span><span class="n">ascii_pcd_fname</span><span class="p">)</span>
    <span class="n">bpc1</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">point_cloud_from_path</span><span class="p">(</span><span class="n">bin_pcd_fname</span><span class="p">)</span>
    <span class="n">am</span> <span class="o">=</span> <span class="n">cloud_centroid</span><span class="p">(</span><span class="n">apc1</span><span class="p">)</span>
    <span class="n">bm</span> <span class="o">=</span> <span class="n">cloud_centroid</span><span class="p">(</span><span class="n">bpc1</span><span class="p">)</span></div>
    <span class="k">assert</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">am</span><span class="p">,</span> <span class="n">bm</span><span class="p">))</span>
</pre></div>

          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper"><div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../../../index.html">Documentation overview</a><ul>
  <li><a href="../../index.html">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2018, Daniel Maturana.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.1</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
    </div>

    

    
  </body>
</html>